#ifndef CONTROLLER_H
#define CONTROLLER_H

#include "scene.h"
#include "output_device.h"
#include "id_generator.h"
#include <vector>

// for now just a stub
class Controller
{
public:
  Controller(Scene& s) : scene_(s) {}
  void registerOutputDevice(OutputDevice* dev) { outputs.push_back(dev); }
  void unregisterOutputDevice(OutputDevice* dev)
  {
    std::vector<OutputDevice*>::iterator k;
    for (std::vector<OutputDevice*>::iterator i = outputs.begin(), ie = outputs.end(); i != ie; ++i)
    {
      if (*i == dev) { k = i; break; }
    }
    outputs.erase(k);
  }
  void rotateCamera(int dx, int dy)
  {
    scene_.camera().rotate(dx,dy);
    updateOutputs();
  }
  void zoomCamera(int dz)
  {
    scene_.camera().zoom(dz);
    updateOutputs();
  }

  Scene& scene() { return scene_; }
  void pickingEvent(IdGenerator::id_type i) { std::cerr << "Picking event : " << i << std::endl; }
private:
  void updateOutputs()
  {
    for (std::vector<OutputDevice*>::iterator i = outputs.begin(), ie = outputs.end(); i != ie; ++i)
    {
      (*i)->updateCamera();
      (*i)->redraw();
    }
  }

  Scene& scene_;
  std::vector<OutputDevice*> outputs;
};

#endif // CONTROLLER_H
